package what.basic.list;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Jlistdoubleclick extends MouseAdapter {
String[] s={"java enter","c language","hibernate","visual basic","delphi","asp"};
public Jlistdoubleclick(){
	JFrame jf=new JFrame("JdefaultList");
	Container cp=jf.getContentPane();
	cp.setLayout(new GridLayout(1,2));
	final DefaultListModel lm1=new DataModel2(1);
	final JList lst1=new JList(lm1);
	final DefaultListModel lm2=new DataModel2(2);
	final JList lst2=new JList(lm2);
	lst1.setBorder(BorderFactory.createTitledBorder("book categories"));
	lst1.addMouseListener(new MouseAdapter(){
		public void mouseClicked(MouseEvent e){
			int index;
				if(e.getClickCount()==2){
					index=lst1.locationToIndex(e.getPoint());
					String t=(String)lm1.getElementAt(index);
					lm2.addElement(t);
					lst2.setModel(lm2);
					lm1.removeElementAt(index);
					lst1.setModel(lm1);
				}
		}
	});
	
	lst2.setBorder(BorderFactory.createTitledBorder("your selection:"));
	lst2.addMouseListener(new MouseAdapter(){
		public void mouseClicked(MouseEvent e){
			int index;
				if(e.getClickCount()==2){
					index=lst2.locationToIndex(e.getPoint());
					String t=(String)lm2.getElementAt(index);
					lm1.addElement(t);
					lst1.setModel(lm1);
					lm2.removeElementAt(index);
					lst2.setModel(lm2);
				}
		}
	});
	cp.add(new JScrollPane(lst2));
	cp.add(new JScrollPane(lst1));
	jf.pack();
	jf.setVisible(true);
	jf.addWindowListener(new WindowAdapter(){
		public void windowClosing(WindowEvent e){
			System.exit(0);
		}
	});
}
public static void main(String[] args){
	new Jlistdoubleclick();
}
class DataModel2 extends DefaultListModel{
	DataModel2(int flag){
		if (flag==1){
		for(int i=0;i<s.length;i++){
			addElement((i+1)+"."+s[i]);
		}}
	}

}

}
